package com.lt.config;

import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.region.Region;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author :liteng
 * @Time : 2023-10-22 16:24
 */
@Configuration
@Data
public class TencentCOSConfig {
    @Value("${tencent.SecretId}")
    private String secretId;

    @Value("${tencent.SecretKey}")
    private String secretKey;

    @Value("${tencent.region}")
    private String region;

    @Value("${tencent.bucketName}")
    private String bucketName;

    @Value("${tencent.url}")
    private String path;

    @Bean
    public COSClient cosClient(){
        // 1 初始化用户身份信息（secretId, secretKey）。
        COSCredentials cred = new BasicCOSCredentials(this.secretId, this.secretKey);
        // 2 设置 bucket 的区域
        Region region = new Region(this.region);
        ClientConfig clientConfig = new ClientConfig(region);
        // 3 生成 cos 客户端。
        return new COSClient(cred, clientConfig);

    }

}
